/**
全库基本检索
*/		
function generalSearch(display,condition,basepath){
	var win = document.getElementById('resultlist').contentWindow;
	var datatype = condition;
    var disstr = getDisnameStrbasic(); 
 	var basiccol = ge("basic_col").value;
	var basicvalue = ge("basic_colvalue").value;
	var basicspecial = ge("basic_special").value;
	var startyear = ge("startyear").value;
	var endyear = ge("endyear").value;
	var issyn = null;//ge("issyn").value; 
	if(disstr == ''){
		alert("请选择疾病名称！");
		return;
	}
	onestr = "?disnamestr="+disstr+"&startyear="+startyear+"&endyear="+endyear+"&datatype="+datatype+"&issyn="+issyn+"&basiccol="+basiccol +"&basicvalue="+basicvalue+"&basicspecial="+basicspecial+"&searchtype=basic_search";
 	document.getElementById("resultlist").src= basepath +"search/dosearch.do"+onestr;
 	loadYearGroupdata(onestr,basepath);
 	loadPenameGroupdata(onestr,basepath);
}
function basiclinchuang(display,condition,basepath){
 	var datatype = condition;
    var disstr = getDisnameStrbasic(); 
 	var basiccol = ge("basic_col").value;
	var basicvalue = ge("basic_colvalue").value;
	var basicspecial = ge("basic_special").value;
	var startyear = ge("startyear").value;
	var endyear = ge("endyear").value;
	var issyn = null;//ge("issyn").value; 
	if(disstr == ''){
		alert("请选择疾病名称！");
		return;
	}
	onestr = "?disnamestr="+disstr+"&startyear="+startyear+"&endyear="+endyear+"&datatype="+datatype+"&issyn="+issyn+"&basiccol="+basiccol +"&basicvalue="+basicvalue+"&basicspecial="+basicspecial+"&searchtype=basic_search";
	openwindow(basepath + 'stat/statindex.do'+onestr,'1280','960','');
	//document.getElementById("resultlist").src= basepath +"search/dosearch.do"+onestr; 
}
/**
高级检索
*/
function advlinchuang(datatype,basepath){
    
	var divid = "txt_";
	var onestr = "?searchtype=advsearch&";
	var startyear = ge("startyear_adv").value;
	 
	var endyear = ge("endyear_adv").value;
	var disstr = getDisnameStr(); 
	if(disstr == ''){
		alert("请选择疾病名称！");
		return;
	}
	var datatypestr = "";
	var datatypearr = document.getElementsByName("datatype");
	if(datatypearr != null)
	for(var i =0;i<datatypearr.length;i++){
		var temp = datatypearr[i];
		if(temp.checked){
			datatypestr+=temp.value; 
			datatypestr+=',';
		}
	} 
	if(datatypestr == ',')
		datatypestr = '';
	for(var i=1; i<=19; i++){
		var divcur = divid + i + "_value";
		var curobj = ge(divcur);
		var curvalueStr = divid+i+"_value";
		var curlogicStr = divid+i+"_logical";
		var curselStr = divid+i+"_sel";
		var curspecialStr = divid+i+"_special";
		
		if(curobj != undefined ){
			if(curobj.value != "")
			{
				var curvalue = curobj.value;
				if(i !=1){
					var curlogic = ge(curlogicStr).value;
				}else{
					var curlogic = 0 ;
				}
				var cursel = ge(curselStr).value;
				var curspecial = ge(curspecialStr).value;
				if(onestr.indexOf("&")!=-1){
					onestr = onestr + "&";
				}
				onestr = onestr + curvalueStr+"="+curvalue+"&"+curlogicStr+"="+curlogic+"&"+curselStr+"="+cursel+"&"+curspecialStr+"="+curspecial;
			}
		}
		
	}  
	 
    onestr +="&disnamestr="+disstr+"&startyear="+startyear+"&endyear="+endyear+"&datatype="+datatypestr; 
    openwindow(basepath + 'stat/statindex.do'+onestr,'1280','960','');
	 
}
//二次检索
function generalSecondSearch(condition,basepath){
	var win = ge('resultlist').contentWindow;
	var onesql = win.document.getElementById('onesql').value;
	var onekeyword = win.document.getElementById('onekeyword').value;
	var disstr = getDisnameStrbasic();
	if(disstr == ''){
		alert("请选择疾病名称！");
		return;
	}
	//alert(onesql);
	var divid = "txt_";
	var onestr = "";
	var basiccol = ge("basic_col").value;
	var basicvalue = ge("basic_colvalue").value;
	var basicspecial = ge("basic_special").value;
	var startyear = ge("startyear").value;
	var endyear = ge("endyear").value;
	if(isNull(basicvalue)){
		alert("检索条件不能为空!");
		document.getElementById("basic_colvalue").focus();
	    return;
	}
	onestr = "?disnamestr="+disstr+"&startyear="+startyear+"&endyear="+endyear+"&basiccol="+basiccol +"&searchtype=basic_search&basicvalue="+basicvalue+"&basicspecial="+basicspecial+"&onekeyword="+onekeyword;
	 
	if(onesql !=null && onesql!=""){
		onestr = onestr + "&onesql=" + encodeURIComponent(onesql);
	}
	document.getElementById("resultlist").src=basepath +"search/dosearch.do"+onestr;
	loadYearGroupdata(onestr,basepath);
 	loadPenameGroupdata(onestr,basepath); 
}
function loadYearGroupdata(paramstr,basePath){
	 
	$.ajax({   
        type:'GET'  
        ,url: basePath + 'search/yeargroup.do'+encodeURI(paramstr)  
        ,data:'',                           
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",  
        beforeSend:function(data){   
            $('#messagediv1').html('数据加载中......');
        }//发送请求前   
        ,success:function(data){   
        	  
            $('#yeargroup').html(data);    
        }//请求成功后   
        ,error:function(data){   
            $('#messagediv1').html('数据加载失败.')   
        }//请求错误   
        ,complete:function(data){    

        }   
    });    
}
function loadPenameGroupdata(paramstr,basePath){
	
	$.ajax({   
        type:'GET'  
        ,url: basePath + 'search/pernamegroup.do'+encodeURI(paramstr)   
        ,data:'',                           
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",   
        beforeSend:function(data){   
            $('#messagediv2').html('数据加载中......');
        }//发送请求前   
        ,success:function(data){    
            $('#pgroup').html(data);    
        }//请求成功后   
        ,error:function(data){   
            $('#messagediv2').html('数据加载失败.')   
        }//请求错误   
        ,complete:function(data){    

        }   
    });    
}
function getDisnameStrbasic(){
	var disnamestr = "";
	var disnamearr = document.getElementsByName("disnamebasic");
	if(disnamearr != null)
	for(var i =0;i<disnamearr.length;i++){
		var temp = disnamearr[i]; 
		if(temp.checked){
			disnamestr+=temp.value; 
			disnamestr+=',';
		}
	} 
	if(disnamestr == ',')
		disnamestr = ''; 
	return disnamestr;
}
function getDisnameStr(){
	var disnamestr = "";
	var disnamearr = document.getElementsByName("disname");
	if(disnamearr != null)
	for(var i =0;i<disnamearr.length;i++){
		var temp = disnamearr[i];
		if(temp.checked){
			disnamestr+=temp.value; 
			disnamestr+=',';
		}
	} 
	if(disnamestr == ',')
		disnamestr = ''; 
	return disnamestr;
}
/**
高级检索
*/
function advSearch(datatype,basepath){
    
	var divid = "txt_";
	var onestr = "?searchtype=advsearch&";
	var startyear = ge("startyear_adv").value;
	var endyear = ge("endyear_adv").value;
	var disstr = getDisnameStr(); 
	if(disstr == ''){
		alert("请选择疾病名称！");
		return;
	}
	var datatypestr = "";
	var datatypearr = document.getElementsByName("datatype");
	if(datatypearr != null)
	for(var i =0;i<datatypearr.length;i++){
		var temp = datatypearr[i];
		if(temp.checked){
			datatypestr+=temp.value; 
			datatypestr+=',';
		}
	} 
	if(datatypestr == ',')
		datatypestr = '';
	for(var i=1; i<=19; i++){
		var divcur = divid + i + "_value";
		var curobj = ge(divcur);
		var curvalueStr = divid+i+"_value";
		var curlogicStr = divid+i+"_logical";
		var curselStr = divid+i+"_sel";
		var curspecialStr = divid+i+"_special";
		
		if(curobj != undefined ){
			if(curobj.value != "")
			{
				var curvalue = curobj.value;
				if(i !=1){
					var curlogic = ge(curlogicStr).value;
				}else{
					var curlogic = 0 ;
				}
				var cursel = ge(curselStr).value;
				var curspecial = ge(curspecialStr).value;
				if(onestr.indexOf("&")!=-1){
					onestr = onestr + "&";
				}
				onestr = onestr + curvalueStr+"="+curvalue+"&"+curlogicStr+"="+curlogic+"&"+curselStr+"="+cursel+"&"+curspecialStr+"="+curspecial;
			}
		}
		
	}  
	 
    onestr +="&disnamestr="+disstr+"&startyear="+startyear+"&endyear="+endyear+"&datatype="+datatypestr; 
	document.getElementById("resultlist").src=basepath +"search/dosearch.do"+onestr;
	loadYearGroupdata(onestr,basepath);
 	loadPenameGroupdata(onestr,basepath);
}
function AddRowEx(divid, divindex, divcount) {
 	try { 
 		 
 		
		if (!ge(divindex) || !ge(divcount) || ge(divindex).value == ge(divcount).value) {
			return
		}
		var curID = parseInt($("#" + divindex).val());
		var copyID = curID + 1;
		var curTrID = divid + "_" + curID.toString();
		var copyTrID = divid + "_" + copyID.toString();
		var copyHtml = "";
		if ($("#" + copyTrID).html() != null) {
			$("#" + copyTrID).show()
		} else {
			var cloneObj = $("#" + curTrID).clone();
			if (curID == 1) {
				if (cloneObj.find("td:first") != null) {
					cloneObj.find("td:first").remove()
				}
				if (cloneObj.find("span:first") != null) {
					cloneObj.find("span:first").remove()
				}
				var logicalTd = $("#hidden_logical_" + divid).html();
				if (logicalTd != "") {
					var reg = /{key}/g;
					logicalTd = logicalTd.replace(reg, copyTrID);
					cloneObj = cloneObj.prepend(logicalTd)
				}
			}
			copyHtml = $("<div></div>").append(cloneObj).html();
			var reg1 = eval("/" + curTrID + "/g");
			copyHtml = copyHtml.replace(reg1, divid + "_" + copyID.toString());
			if (copyHtml != "") {
				$("#" + curTrID).after(copyHtml)
			}
		}
		var objvalue = ge(copyTrID + "_value1");
		if (objvalue != null) {
			objvalue.value = ""
		}
		objvalue = ge(copyTrID + "_value2");
		if (objvalue != null) {
			objvalue.value = ""
		}
		ge(divindex).value = copyID.toString();
		var obj = ge(copyTrID + "_sel");
		if (!obj) {
			obj = ge(copyTrID + "_sel1")
		}
		if (obj) {
			obj.options[copyID - 1].selected = true;
			obj.onchange()
		}
	} catch (e) {}
}
function DeleteRow(h, c, b) {
	try {
		if (ge(c).value == "1") {
			return
		} else {
			var g = parseInt(ge(c).value);
			var f = h + "_" + g;
			var a = ge(f + "_value1");
			if (a != null) {
				a.value = ""
			}
			a = ge(f + "_value2");
			if (a != null) {
				a.value = ""
			}
			SetDisplayValue(f, "none");
			f;
			g--;
			ge(c).value = g
		}
	} catch (d) {
		return
	}
}
function SetDisplayValue(b, a) {
	var c = ge(b);
	if (c) {
		if (c.style) {
			c.style.display = a
		}
	}
}
/**
 * 获取页面对象
 * @param a
 * @returns
 */
function ge(a) {
	return document.getElementById(a)
}
function test(str)
{
    var test=document.getElementById(str).value;
    if(/[\':;*?~`!@#$%^&+={}\[\]\<\>\(\),]/.test(test))
     {
    	
        alert("不能输入特殊字符!");
        document.getElementById(str).value="";
        document.getElementById(str).focus();
        return false;
     }
}
 


function SignVal1(a) {}
function SignVal(f, c, d) {
	if (c == "sign") {
		d = (d) ? d : ((window.event) ? window.event : "");
		var a = d.keyCode ? d.keyCode : d.which;
		if ((a == 39 && document.all) || a == 34 || a == 59) {
			alert("不能输入：' \" ; 等字符！");
			if (d.keyCode) {
				d.keyCode = 0
			}
		}
	} else {
		if (c == "value") {
			if (window.clipboardData) {
				var b = clipboardData.getData("text");
				if (b.indexOf("'") != -1 || b.indexOf('"') != -1 || b.indexOf(";") != -1 || b.indexOf("\\") != -1 || b.indexOf("/") != -1) {
					alert("不能输入：'、\"、; 等字符！");
					return false
				}
			}
		} else {
			if (c == "input") {
				var b = f.value;
				if (b.indexOf("'") != -1 || b.indexOf('"') != -1 || b.indexOf(";") != -1 || b.indexOf("<") != -1 || b.indexOf(">") != -1 || b.indexOf("\\") != -1 || b.indexOf("/") != -1) {
					return false
				}
			}
		}
	}
	return true
}
function resetAll(){
 	var   obj   =   document.all.tags("input"); 
	for(i=0;i <obj.length;i++){ 
	    if(obj[i].type== "text"){ 
	            obj[i].value   =   ""; 
	    } 
	}
 
}



function issynCheck(){
	   var colselected = document.getElementById("basic_col").value;
	   if('DISNAME' == colselected){
	   		var obj = document.getElementById("issyn");
	   		obj.disabled = false; 
	   		obj.checked = true;
	   }else{
	   		var obj = document.getElementById("issyn");
	   		obj.disabled = true; 
	   		obj.checked = false;
	   }
}
function resetAll(){
 	var   obj   =   document.all.tags("input"); 
	for(i=0;i <obj.length;i++){ 
	    if(obj[i].type== "text"){ 
	            obj[i].value   =   ""; 
	    } 
	}
 
}
/**
	控制各个检索模块DIV的显示
*/
function searchViewDisplay(divid){
	 var div1 = document.getElementById(divid); 
	 var iframeobj = document.getElementById("resultlist");
    if('basic_search' == divid){
    	 if(div1.style != null){
    		 div1.style.display="";
     		 if(null != iframeobj)
    		 	iframeobj.src = '<%=basePath%>/search/dosearch.do?searchtype=basic_search';
    	}else{
	     	hidediv('advsearch');
	     	hidediv('advmod');
	     	hidediv('adveng');
	     	hidediv('advbook');
    	}
    } else if('advsearch' == divid){
    	 if(div1.style != null){
    		 div1.style.display="";
    		 if(null != iframeobj)
    		 	iframeobj.src = '<%=basePath%>/search/dosearch.do?searchtype=advsearch';
    	}else{
	     	hidediv('basic_search');
	     	hidediv('advmod');
	     	hidediv('adveng');
	     	hidediv('advbook');
    	}
    } else if('advmod' == divid){
    	 if(div1.style != null){
    		 div1.style.display="";
    		 if(null != iframeobj)
    		 	iframeobj.src = '<%=basePath%>/search/dosearch.do?searchtype=advmod';
	     }else{
	     	hidediv('basic_search');
	     	hidediv('advsearch');
	     	hidediv('adveng');
	     	hidediv('advbook');
	     }
    } else if('adveng' == divid){
    	if(div1.style != null){
    		 div1.style.display="";
    		 if(null != iframeobj)
    		 	iframeobj.src = '<%=basePath%>/search/dosearch.do?searchtype=adveng';
    	}else{
	     	hidediv('basic_search');
	     	hidediv('advmod');
	     	hidediv('advsearch');
	     	hidediv('advbook');
    	}
    } else if('advbook' == divid){
    	if(div1.style != null){
    		 div1.style.display="";
    		 if(null != iframeobj)
    		 	iframeobj.src = '<%=basePath%>/search/dosearch.do?searchtype=advbook';
    	}else{
    	hidediv('basic_search');
    	hidediv('advmod');
    	hidediv('advsearch');
    	hidediv('adveng');
    	}
    } 
}
/**
	隐藏DIV显示
*/
function hidediv(hidiv){
	 var obj = document.getElementById(hidiv);
	  if(div1.style != null)
    		 div1.style.display="none";
}
